var boardBasicMixin = function () {
  return {
    computed: {
      currentMenu: function () {
        var activeMenu = this.activeMenu;
        var menus = this.menus;
        var menu = _.find(menus, {
          name: activeMenu[0]
        });
        if (menu === undefined) {
          return null;
        }

        var subMenus = menu.subMenus;
        if (subMenus) {
          menu = _.find(subMenus, {
            name: activeMenu[1]
          });
        }
        return menu;
      }
    },

    data: function () {
      return {
        loading: false,
        basePath: SysUtil.getBasePath(),
        activeMenu: null,
        menus: [],
        user: null
      };
    },

    created: function () {
      this.loading = true;
      var self = this;
      this.getUser().then(function (user) {
        self.user = user;
        self.activeMenu = self.getActiveMenu();
        self.loading = false;
      }).catch(function () {
        self.loading = false;
      });
    },

    methods: {
      getUser: function () {
        return SysUtil.getUser().then(function (user) {
          return user;
        });
      },

      getActiveMenu: function () {
        var obj = SysUtil.getPathParam();
        var activeMenu;
        if (obj === null) {
          activeMenu = '';
        } else {
          activeMenu = obj.url;
        }

        if (SysUtil.isEmpty(activeMenu)) {
          activeMenu = window.sessionStorage.getItem('equipmentBoardMenu');
        }

        if (SysUtil.isEmpty(activeMenu)) {
          var menus = this.menus;
          if (menus.length === 0) {
            return [''];
          }
          activeMenu = menus[0].name;
        }
        return [activeMenu];
      },

      menuClick: function (menu) {
        var name = menu.name;
        if (this.activeMenu[0] === name) {
          return;
        }
        this.activeMenu = [name];
      },

      menuCommand: function (menu, type) {
        if (this.activeMenu[1] === type) {
          return;
        }
        this.activeMenu = [menu.name, type];
      },

      toBack: function () {
        var basePath = this.basePath;
        location.href = basePath + "/datav/index.html?autoLogin=autoLogin";
      }
    }
  };
}();
